import ucApi from "@rc/apis/uc/index.mjs";
import ecsApi from "@rc/apis/ecs/index.mjs";
import coursewareApi from "@rc/apis/rc/courseware.mjs";
export default function (vm) {
    return [
        {
            type: "remoteSelect",
            label: "授课老师",
            key: "professorId",
            property: {
                placeholder: "请输入授课老师姓名",
                clearable: true,
                options: [],
                props: {
                    label: "label",
                    value: "value"
                },
                remoteMethod(item, query) {
                    if (StringUtil.hasLength(query)) {
                        ecsApi.queryTeacherList({
                            data: { userName: query },
                            success: ({ data }) => {
                                item.options = data.map((i) => ({
                                    label: `${i.userName}-${i.schoolName||'无'}-${i.dptName||'无'}`,
                                    value: i.userId
                                }));
                            }
                        });
                    } else {
                        item.options = [];
                    }
                }
            }
        },
        {
                type: "input",
                label: "资源名称",
                key: "name",
                property: {
                    type: "input",
                    placeholder: '请输入资源名名称',
                }
        },
        {
                type: "input",
                label: "vid",
                key: "videoVid",
                property: {
                    type: "input",
                    placeholder: '请输入vid',
                }
        },
        {
                type: "input",
                label: "资源id",
                key: "resourceId",
                property: {
                    type: "input",
                    placeholder: '请输入资源id',
                }
        },
        {
                type: "remoteSelect",
                label: "修改人",
                key: "updateUserId",
                property: {
                    placeholder: "请输人修改人姓名",
                    clearable: true,
                    options: [],
                    props: {
                        label: "label",
                        value: "value"
                    },
                    remoteMethod(item, query) {
                        if (StringUtil.hasLength(query)) {
                            ucApi.queryUserList({
                                data: { userName: query },
                                success: ({ data }) => {
                                    item.options = data.map((i) => ({
                                        label: i.userName + " - " + i.schoolName,
                                        value: i.userId
                                    }));
                                }
                            });
                        } else {
                            item.options = [];
                        }
                    }
                }
        },
        {
            type: "input",
            label: "文件名称",
            key: "sourceFileName",
            property: {
                type: "input",
                placeholder: '请输入文件名称',
            }
        },
        {
            type: "remoteSelect",
            label: "上传人",
            key: "uploadUserId",
            property: {
                placeholder: "请输人上传人",
                clearable: true,
                options: [],
                props: {
                    label: "label",
                    value: "value"
                },
                remoteMethod(item, query) {
                    if (StringUtil.hasLength(query)) {
                        ucApi.queryUserList({
                            data: { userName: query },
                            success: ({ data }) => {
                                item.options = data.map((i) => ({
                                    label: i.userName + " - " + i.schoolName,
                                    value: i.userId
                                }));
                            }
                        });
                    } else {
                        item.options = [];
                    }
                }
            }
    },
    {
        type: "pickerSelect",
        label: "上传时间",
        key: "uploadDate",
        property: {
            type: "selectPickerLimit",
            options: [
                {
                    label: "最近一周",
                    model: {
                        start: vm.formatDateStart(vm.beforeWeek()),
                        end:  vm.formatDateNow(new Date),
                        label: "最近一周",
                    }
                },
                {
                    label: "最近一月",
                    model: {
                        start:  vm.formatDateStart(vm.beforeMonth()),
                        end: vm.formatDateNow(new Date),
                        label: "最近一月"
                    },
                    selected: true,
                },
                {
                    label: "最近一年",
                    model: {
                        start: vm.formatDateStart(vm.beforeYear()),
                        end: vm.formatDateNow(new Date),
                        label: "最近一年"
                    }
                },
                {
                    label: "自定义时间",
                    model: {
                        start: "",
                        end: "",
                        label: "自定义时间"
                    }
                }
            ],
            "autoSet": true
        },
        change(mode) {
            if(!mode ||( !mode.start && !mode.end)){
                vm.pickerMinDate = '';
            }
            const selectPickerLimit = vm.$refs.veFiltrate.getChildMap().uploadDate.getRef().$refs.selectPickerLimit;
            if(selectPickerLimit){
                const picker = selectPickerLimit.$refs.rangePicker;
                if(picker){
                    if (mode && ['最近一月','最近一年','最近一周'].includes(mode.label)) {
                        picker.properties.disabled = true;
                    }
                    if (mode && mode.label === '自定义时间') {
                        picker.properties.disabled = false;
                        picker.properties.pickerOptions = {//添加时间限制时间跨度一年
                            onPick: obj => {
                                if(obj.minDate) {
                                    vm.pickerMinDate = new Date(obj.minDate).getTime();
                                }
                            },
                            disabledDate: time => {
                                if (vm.pickerMinDate) {
                                    const day1 = 365 * 24 * 3600 * 1000;
                                    let maxTime = vm.pickerMinDate + day1;
                                    let minTime = vm.pickerMinDate - day1;
                                    return time.getTime() > maxTime || time.getTime() < minTime;
                                }
                            }
                        };
                    }
                }
            }
        },
    },
    {
		type: "select",
		label: "打点情况",
        getData: function getData() {
            const data = coursewareApi.questionDotsTypeList()||{};
            let result = {};
            data.forEach((dot)=>{
                result[dot.code] = dot.name;
            });
            return result;
        },
		key: "isDot",
		property: { clearable: true, placeholder: "请选择" }
	},
    ];
}
